package com.kfm.boot.http;

import cn.hutool.http.Header;
import cn.hutool.http.HttpRequest;
import cn.hutool.json.JSONUtil;
import com.kfm.boot.commons.Constant;
import com.kfm.boot.entity.Message;
import com.kfm.boot.entity.Question;

import java.util.ArrayList;

public class HttpExample {

    public static String send(String url, String msg) {
        ArrayList<Message> messages = new ArrayList<>();
        messages.add(new Message("user",msg));
        Question question = new Question(Constant.GPT_35_TURBO, messages);
        String jsonStr = JSONUtil.toJsonStr(question);
        return HttpRequest.post(url)
                .header(Header.CONTENT_TYPE, "application/json")//头信息，多个头信息多次调用此方法即可
                .header(Header.AUTHORIZATION, "Bearer " + Constant.API_KEY)
                .body(jsonStr)// 请求体内容
                .execute().body();
    }
}
